﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Model;
using IBLL.Controller;
using Model.Controller;
using CenterDateAchieve.Forms;
using IBLL.View;

namespace CenterDateAchieve
{
    public partial class TaskDefineForm : EditFormBase, ITaskDefineView
    {
        public TaskDefineForm()
        {
            InitializeComponent();
        }
        private const string Model = "UpLoad";

        private void TaskDefineForm_Load(object sender, EventArgs e)
        {
            
        }

        public override void OnAdjustUI(EntityState editStat, IDataTrans data)
        {
            if (editStat == EntityState.Edit)
            {
                this.txt_Code.Enabled = false;
                this.btDel.Enabled = true;
            }
            else
            {
                this.txt_Code.Enabled = true;
                this.btDel.Enabled = false;
            }
        }
        public override void BeforeSaveAction(IDataTrans data)
        {
            Entity entity = ((DataTrans)data).Entity;
            string model = Model;
            if (radDown.Checked)
            {
                model = "DownLoad";
            }
            foreach (ColumnDefine col in entity.Cols)
            {
                if (col.Column == "model")
                {
                    col.Value = model;
                }
            }
        }
        public override void OnSetDataToView(EntityState editStat, IDataTrans data)
        {
            base.OnSetDataToView(editStat, data);
            Entity entity = ((DataTrans)data).Entity;
            string model=string.Empty;
            foreach (ColumnDefine col in entity.Cols)
            {
                if (col.Column == "model")
                {
                    model =Convert.ToString( col.Value);
                }
            }
            if (model == Model)
            {
                radUp.Checked = true;
            }
            else
            {
                radDown.Checked = true;
            }
        }
        #region IViewForm 成员

        public event EventHandler ExitAction;

            
        #endregion

        private void btExit_Click(object sender, EventArgs e)
        {
            ExitAction(sender, e);
        }

        private void btNew_Click(object sender, EventArgs e)
        {
            InvokeCreateAction(sender, e);
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            InvokeSaveAction(sender, e);
        }

        private void btDel_Click(object sender, EventArgs e)
        {
            InvokeDeleteAction(sender, e);
        }
        private void InvokePreviewAction(object sender, EventArgs e)
        { 
            if(PreviewAction!=null)
                PreviewAction(sender, e);
        }
        private void btPreview_Click(object sender, EventArgs e)
        {
            InvokePreviewAction(sender, e);
        }

        #region ITaskDefineView 成员

        public event EventHandler PreviewAction;

        #endregion
    }
}
